package com.atguigu.tingshu.order.adapter.impl;

import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
import com.atguigu.tingshu.order.adapter.PayWay;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class WxPayWayImpl implements PayWay {

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private RabbitService rabbitService;

    /**
     * 是否支持微信支付
     *
     * @param payWay
     * @return
     */
    @Override
    public Boolean supportPayWay(String payWay) {
        return SystemConstant.ORDER_PAY_WAY_WEIXIN.equals(payWay);
    }


    /**
     * 微信支付
     */
    @Override
    public void payWay(OrderInfoVo orderInfoVo, String orderNo, Long userId) {
        log.info("微信支付逻辑");
        // 1.保存订单信息
        orderInfoService.saveOrderInfo(orderNo, orderInfoVo, userId);
        // 2.向延迟插件的队列中发送一个订单消息(让该订单在30min之后订单状态修改为已关闭)
        rabbitService.sendDealyMessage(
                MqConst.EXCHANGE_CANCEL_ORDER,//取消订单交换机
                MqConst.ROUTING_CANCEL_ORDER,//取消订单路由
                orderNo,
                MqConst.DELAY_TIME//延迟时间30min
        );


    }


}
